import pymysql

class DB:
    def __init__(self,host,user,pwd,database):
        self.conn = pymysql.connect(host=host, user=user, password=pwd,database=database)
        self.cursor = self.conn.cursor()

    #执行查询，返回结果
    def select(self, sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()

    #关闭连接
    def close(self):
        self.cursor.close()
        self.conn.close()

